// 页面路径：store/index.js 
import Vue from 'vue'
import Vuex from 'vuex'
import requestApi from '../api.js'

Vue.use(Vuex); //vue的插件机制
const formData = { //自我介绍组件的
	name: '',
	age: '',
	work: '',
	brithday: '',
	single: '',
	wx: '',
	qq: '',
	phone: '',
	email: '',
	address: '',
	student: '',
	major: '',
	status: '',
	evaluation: '',
	job: '',
	myself: ''

}
const keywordList = {
	keyword: '',
	startKeyWord: ''
}
const skillList = [{
		content: ''
	},
	{
		content: ''
	},
	{
		content: ''
	},
	{
		content: ''
	},
]
const obj = [{
		project: '',
		label: '工作公司：',
		placeholder: "请输入单位名称",
		type: 'text'
	},
	{
		project: '',
		label: '职位：',
		placeholder: "请输入公司职位",
		type: 'text'
	},
	{
		project: '',
		label: '项目名：',
		placeholder: "请输入做过的项目",
		type: 'text'
	},
	{
		project: '',
		label: '项目描述：',
		placeholder: "请简单描述下当前项目",
		type: 'textarea'
	},
	{
		project: '',
		label: '技术栈：',
		placeholder: "请输入当前项目使用到的技术",
		type: 'textarea'
	},
	{
		project: '',
		label: '责任描述：',
		placeholder: "请输入你在当前项目中都做了那些,使用空格进行换行，如：1、111",
		type: 'textarea'
	},
]
const projectList = [
	obj
]
//Vuex.Store 构造器选项
const store = new Vuex.Store({
	state: { //存放状态
		oneList: uni.getStorageSync('oneList') || formData,
		twoKeyList: uni.getStorageSync('twoKeyList') || keywordList,
		twoSkillList: uni.getStorageSync('twoSkillList') || skillList,
		threeList: uni.getStorageSync('threeList') || projectList,
		//首页keywrod的数据处理
		showkeyword: [],
		introduceMyself:'',//自我介绍
		PersonalInformation:{},//个人信息
		skillwrod: [],//技能关键字
		skillList:[],//技能介绍
		projectList: [],//项目介绍
		aboutMyList: '',//关于我们的数据
		announcementList: '',//公告
		loginOut: false,//
	},
	mutations: {
		//获取简历模板数据进行重新赋值
		setResume(state,val){
			console.log(val,'简历数据')
			state.oneList = val.oneList;
			state.threeList = val.threeList;
			state.twoKeyList = val.twoKeyList;
			state.twoSkillList = val.twoSkillList;
		},
		//设置页面的数据进行处理
		settingList(state, val){
			console.log(val)
			if(val.type == 3){//关于我们
				console.log('关于我们进行获取',val.data)
				state.aboutMyList = val.data.data[0].data
			}else if(val.type == 5){//公告数据
				console.log('公告数据进行获取',val.data)
				state.announcementList = val.data.data[0].data
			}else if( val.type == 4){//退出登录，直接跳转页面
				state.loginOut = true
			}
		},
		//处理简历格式中的数据
		formatList(state,val){
			console.log('请求=========',val);
			const res = val.data[0].data;
			console.log(val.data[0],val.data[0].data.twoKeyList.startKeyWord.split('-'))
			state.showkeyword = res.twoKeyList.startKeyWord.split('-');
			state.introduceMySelf = res.oneList.myself;
			state.PersonalInformation = res.oneList;
			state.skillwrod = res.twoKeyList.keyword.split('-');
			state.skillList = res.twoSkillList;
			state.projectList = res.threeList;
		},
		//第三个组件中的添加====简历模板中的
		addList(state) {
			state.threeList.push(JSON.parse(JSON.stringify(obj)));
			console.log(state.threeList,'添加简历')
		},
		// 第三个组件中的删除====简历模板中的
		deleteList(state, k) {
			state.threeList.splice(k, 1);
		},
		//第二个组件====简历模板中的
		twoAddList(state) {
			const con = {
				content: ''
			};
			state.twoSkillList.push(con);
		},
		//第二个组件====简历模板中的
		twodeletaList(state, k) {
			state.twoSkillList.splice(k, 1);
		},
		
	},
	actions:{
		//请求注册过得简历
		requestProject({commit}){
			const openid = uni.getStorageSync('openid') || '';
			requestApi('writeProject',{openid, type: 2})
			.then(res=>{
				console.log(res,'简历数据获取')
				if(res.result.status === 'S' && res.result.data.data.length>0){
					commit('formatList',res.result.data)
				}
			}).catch(msg=>{
				console.log(msg)
				uni.showToast({
					title: msg.message,
					icon:'none'
				})
			})
		},
	editRequestList({commit}, k){
		console.log(k,'zhi=========');
			const openid = uni.getStorageSync('openid') || '';
			requestApi('writeProject',{openid, type: k})
			.then(res=>{
				if(res.result.status === 'S'){
					console.log(res.result.data)
					commit('settingList',{type:k,data:res.result.data})
				}
			}).catch(msg=>{
				uni.showToast({
					title: msg.message,
					icon:'none'
				})
			})
	},
	}
	
})
export default store
